import E from "wangeditor"
const { BtnMenu } = E
let _this = this
export default class AlertMenu extends BtnMenu {
  constructor(editor) {
    const $elem = E.$(
      `<div class="w-e-menu">
        <i class="nb-html" style="font-size:10px;">HTML</i>
      </div>`
    )
    super($elem, editor)
  }
  clickHandler() {
    this.showSource()
    this.tryChangeActive()
  }
  tryChangeActive() {
    if (_this?.isHTML) this.active()
    else this.unActive()
  }
  showSource() {
    let _this = this
    let _editor = _this.editor
    _this.isHTML = !_this.isHTML
    let _source = _editor.txt.html()
    if (_this?.isHTML) {
      _source = _source.replace(/</g, "&lt;")
    } else {
      _source = _editor.txt.text().replace(/&lt;/g, "<").replace(/&gt;/gi, ">")
    }
    _editor.txt.html(_source)
  }
}
